package com.ruoyi.web.controller.car;

import java.util.List;

import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ICheyouhuiService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Cheyouhui;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 车友会 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/cheyouhui")
public class CheyouhuiController extends BaseController
{
    private String prefix = "system/cheyouhui";
	
	@Autowired
	private ICheyouhuiService cheyouhuiService;
	
	@RequiresPermissions("system:cheyouhui:view")
	@GetMapping()
	public String cheyouhui()
	{
	    return prefix + "/cheyouhui";
	}
	
	/**
	 * 查询车友会列表
	 */
	@RequiresPermissions("system:cheyouhui:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Cheyouhui cheyouhui)
	{
		startPage();
        List<Cheyouhui> list = cheyouhuiService.selectCheyouhuiList(cheyouhui);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出车友会列表
	 */
	@RequiresPermissions("system:cheyouhui:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Cheyouhui cheyouhui)
    {
    	List<Cheyouhui> list = cheyouhuiService.selectCheyouhuiList(cheyouhui);
        ExcelUtil<Cheyouhui> util = new ExcelUtil<Cheyouhui>(Cheyouhui.class);
        return util.exportExcel(list, "cheyouhui");
    }
	
	/**
	 * 新增车友会
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存车友会
	 */
	@RequiresPermissions("system:cheyouhui:add")
	@Log(title = "车友会", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Cheyouhui cheyouhui)
	{
		SysUser user = getSysUser();
		cheyouhui.setPersonId(user.getUserId());
		return toAjax(cheyouhuiService.insertCheyouhui(cheyouhui));
	}

	/**
	 * 修改车友会
	 */
	@GetMapping("/edit/{cheyouhuiId}")
	public String edit(@PathVariable("cheyouhuiId") Integer cheyouhuiId, ModelMap mmap)
	{
		Cheyouhui cheyouhui = cheyouhuiService.selectCheyouhuiById(cheyouhuiId);
		mmap.put("cheyouhui", cheyouhui);
	    return prefix + "/edit";
	}
	/**
	 * 查看车友会
	 */
	@GetMapping("/chakan/{cheyouhuiId}")
	public String chakan(@PathVariable("cheyouhuiId") Integer cheyouhuiId, ModelMap mmap)
	{
		Cheyouhui cheyouhui = cheyouhuiService.selectCheyouhuiById(cheyouhuiId);
		mmap.put("cheyouhui", cheyouhui);
		return prefix + "/chakan";
	}
	
	/**
	 * 修改保存车友会
	 */
	@RequiresPermissions("system:cheyouhui:edit")
	@Log(title = "车友会", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Cheyouhui cheyouhui)
	{		
		return toAjax(cheyouhuiService.updateCheyouhui(cheyouhui));
	}
	
	/**
	 * 删除车友会
	 */
	@RequiresPermissions("system:cheyouhui:remove")
	@Log(title = "车友会", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(cheyouhuiService.deleteCheyouhuiByIds(ids));
	}

	/**
	 * 用户状态修改
	 */
	@Log(title = "车友会", businessType = BusinessType.UPDATE)
	@RequiresPermissions("system:cheyouhui:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(Cheyouhui cheyouhui)
	{
		return toAjax(cheyouhuiService.changeStatus(cheyouhui));
	}
	
}
